home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 March / CMCD0305.ISO / Software / Shareware / Utilitare / emu / Emu8086_Setup_307c.exe / {app} / DEVICES / io.h < prev    next >
Text File  |  2003-06-05  |  2KB  |  104 lines

  1. /*
  2.  This header file can be used to implement
  3.  your own external devices for Emu8086 -
  4.  8086 Microprocessor Emulator.
  5.  Device can be written in C/C++/MS Visual C++
  6.  (for Visual Basic use "IO.BAS" instead).
  7.  
  8.  Supported input / output addresses:
  9.                   15 to 65535 (0000Fh - 0FFFFh)
  10.  
  11.  Version 2.12 of Emu8086 or above is required,
  12.  check this URL for the latest version:
  13.  http://www.emu8086.com
  14.  
  15.  You don't need to understand the code of this
  16.  module, just include this file ("io.h") into your
  17.  project, and use these functions:
  18.  
  19.     unsigned char READ_IO_BYTE(long lPORT_NUM)
  20.     short int READ_IO_WORD(long lPORT_NUM)
  21.  
  22.     void WRITE_IO_BYTE(long lPORT_NUM, unsigned char uValue)
  23.     void WRITE_IO_WORD(long lPORT_NUM, short int iValue)
  24.  
  25.  Where:
  26.   lPORT_NUM - is a number in range: from 15 to 65535.
  27.   uValue    - unsigned byte value to be written to a port.
  28.   iValue    - signed word value to be written to a port.
  29. */
  30.  
  31. const char sIO_FILE[] = "EmuPort.io";
  32.  
  33. unsigned char READ_IO_BYTE(long lPORT_NUM)
  34. {
  35.     unsigned char tb;
  36.  
  37.     char buf[500];
  38.     unsigned int ch;
  39.  
  40.     GetTempPath (499,buf);
  41.  
  42.  
  43.     strcat(buf, sIO_FILE);
  44.  
  45.     FILE *fp;
  46.  
  47.     fp = fopen(buf,"r+");
  48.  
  49.     // Read byte from port:
  50.     fseek(fp, lPORT_NUM, SEEK_SET);
  51.     ch = fgetc(fp);
  52.  
  53.     fclose(fp);
  54.  
  55.     tb = ch;
  56.  
  57.     return tb;
  58. }
  59.  
  60. short int READ_IO_WORD(long lPORT_NUM)
  61. {
  62.     short int ti;
  63.     unsigned char tb1;
  64.     unsigned char tb2;
  65.  
  66.     tb1 = READ_IO_BYTE(lPORT_NUM);
  67.     tb2 = READ_IO_BYTE(lPORT_NUM + 1);
  68.  
  69.     // Convert 2 bytes to a 16 bit word:
  70.     ti = tb2;
  71.     ti = ti << 8;
  72.     ti = ti + tb1;
  73.  
  74.     return ti;
  75. }
  76.  
  77. void WRITE_IO_BYTE(long lPORT_NUM, unsigned char uValue)
  78. {
  79.     char buf[500];
  80.     unsigned int ch;
  81.  
  82.     GetTempPath (499,buf);
  83.  
  84.     strcat(buf, sIO_FILE);
  85.  
  86.     FILE *fp;
  87.  
  88.     fp = fopen(buf,"r+");
  89.  
  90.     ch = uValue;
  91.  
  92.     // Write byte to port:
  93.     fseek(fp, lPORT_NUM, SEEK_SET);
  94.     fputc(ch, fp);
  95.  
  96.     fclose(fp);
  97. }
  98.  
  99. void WRITE_IO_WORD(long lPORT_NUM, short int iValue)
  100. {
  101.     WRITE_IO_BYTE (lPORT_NUM, iValue & 0x00FF);
  102.     WRITE_IO_BYTE (lPORT_NUM + 1, (iValue & 0xFF00) >> 8);
  103. }
  104.